package com.huang.dao;

import com.huang.pojo.User;
import com.huang.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;


public class UserDaotext {
    @Test
    public void text() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> listuser = mapper.getUser();
        for (User user : listuser) {
            System.out.println(user);
        }
        sqlSession.close();
    }

    //根据id查找
    @Test
    public void getUserbyid() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.getUserbyid(1);
        System.out.println(user);
        sqlSession.close();
    }
    //添加用户
    @Test
    public void testAddUser() {
        SqlSession session = MybatisUtils.getSqlSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = new User(6, "秦猪", "123345");
        mapper.addUser(user);
        session.close();
    }
    //修改用户
    @Test
    public void testUpdateUser() {
        SqlSession session = MybatisUtils.getSqlSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = new User(6, "秦疆", "888888");
        mapper.updateUser(user);
        session.close();
    }
    //删除用户
    @Test
    public void testDeleteUser() {
        SqlSession session = MybatisUtils.getSqlSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        mapper.deleteUser(6);
        session.close();
    }
}
